package day7;

import java.util.Scanner;

//狗类
public class Dog extends pet{
    String type;
    public void print(){
        System.out.println("狗基本信息");
        System.out.println("姓名:"+name);
        System.out.println("友好度:"+love);
        System.out.println("健康值:"+health);
        System.out.println("品种:"+type);
    }
    public void eat(){
        System.out.println("狗开始吃狗粮");
    }
}
class Cat extends pet{
    String color;
    public void print(){
        System.out.println("猫基本信息");
        System.out.println("姓名:"+name);
        System.out.println("友好度:"+love);
        System.out.println("健康值:"+health);
        System.out.println("颜色:"+color);
    }
    public void eat(){
        System.out.println("猫开始吃鱼");
    }
}
abstract class pet {
    String name;
    int love=60;
    int health=100;
    //方法写一半，只有声明，没有实现，抽象方法
    public abstract void print();
    public abstract void eat();
}
class TestPet{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入宠物姓名:");
        String name=sc.next();
        System.out.println("请输入宠物类型(1.狗 2.猫)");
        int n=sc.nextInt();
        pet p=null;
        switch (n){
            case 1:
                p=new Dog();
                System.out.print("请输入品种:");
                String type=sc.next();
                //Dog dog=(Dog)p;
                //dog.type=type;
                ((Dog)p).type=type;
                break;
            case 2:
                p=new Cat();
                System.out.print("请输入颜色:");
                String color=sc.next();
                ((Cat)p).color=color;
                break;
            default:break;
        }
        p.name=name;
        p.print();
        p.eat();
    }
}